package part19;

import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Set;
import java.util.TreeSet;

/**
 * @author wcj
 * @Date 2021/6/5 17:19
 * @Version 1.0
 */
public class Part194 {

    public static Set<String> analyze(Class<?> enumClass) {
        System.out.println("-------------Analyzing:" + enumClass + "------");
        System.out.println("Interfaces:");
        for (Type genericInterface : enumClass.getGenericInterfaces()) {
            System.out.println(genericInterface);
        }
        System.out.println("SuperClass:" + enumClass.getSuperclass());
        System.out.println("Methods:");
        TreeSet<String> methods = new TreeSet<>();
        for (Method method : enumClass.getMethods()) {
            methods.add(method.getName());
        }
        System.out.println(methods);
        return methods;
    }

    /**
     * Enum枚举根类中并没有提供values()方法，子类的values()方法是由编译器加上去的。
     * 并且enum不可被继承也是在编译阶段加上了final关键字禁止了其被继承
     * 我们可以通过class对象调用getEnumConstants()获取enum实例，对于一般的类获取的为null
     *
     * @param args
     */
    public static void main(String[] args) {
        Set<String> ExploreMethods = analyze(Explore.class);
        Set<String> EnumMethods = analyze(Enum.class);
        System.out.println(ExploreMethods.containsAll(EnumMethods));
        ExploreMethods.removeAll(EnumMethods);
        System.out.println(ExploreMethods);
    }
}

enum Explore {
    HERE,
    THERE,
}
